public class Solution{
    public static void main(String[] args){
        Solution solution = new Solution();
        String s = "a";
        System.out.println(solution.longestPalindrome(s));
    }
    public String longestPalindrome(String s) {
        if (s ==null){
            return null;
        }
        String res = null;
        int len = s.length();
        int max = 0;
        boolean[][] D=new boolean[len][len];
        for ( int i =0;i<len;i++){
            for ( int j =0;j<=i;j++){
                D[j][i] = s.charAt(i)==s.charAt(j)&&(i-j<=2||D[j+1][i-1]);
                if(D[j][i]){
                    if(i-j+1>max){
                        max = i-j+1;
                        res = s.substring(j,i+1);
                    }
                }
            }
        }
        return res;
    }
}